<html>
<head><meta charset="utf-8"><title>What determines if a type is unqualified in error output? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html">What determines if a type is unqualified in error output?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231253391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253391">(Mar 22 2021 at 01:16)</a>:</h4>
<p>If you run this on nightly:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(auto_traits, negative_impls)]</span><span class="w"></span>

<span class="n">auto</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">NotFeline</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Cat</span><span class="p">;</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">CatCafe</span><span class="p">(</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">Cat</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Dog</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="o">!</span><span class="n">NotFeline</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Cat</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">no_cats_allowed</span><span class="o">&lt;</span><span class="n">A</span>: <span class="nc">NotFeline</span><span class="o">&gt;</span><span class="p">(</span><span class="n">animal</span>: <span class="nc">A</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">no_cats_allowed</span><span class="p">(</span><span class="n">Cat</span><span class="p">);</span><span class="w">             </span><span class="c1">// Should fail</span>
<span class="w">    </span><span class="n">no_cats_allowed</span><span class="p">(</span><span class="n">CatCafe</span><span class="p">(</span><span class="fm">vec!</span><span class="p">[]));</span><span class="w"> </span><span class="c1">// Should fail</span>
<span class="w">    </span><span class="n">no_cats_allowed</span><span class="p">(</span><span class="n">Dog</span><span class="p">);</span><span class="w">             </span><span class="c1">// Should be OK</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>You'll get this in the error output:</p>
<div class="codehilite" data-code-language="none"><pre><span></span><code>   = note: required because it appears within the type `*const Cat`
   = note: required because it appears within the type `Unique&lt;Cat&gt;`
   = note: required because it appears within the type `alloc::raw_vec::RawVec&lt;Cat&gt;`
   = note: required because it appears within the type `Vec&lt;Cat&gt;`
   = note: required because it appears within the type `CatCafe`
</code></pre></div>
<p>Why is <code>Unique</code> unqualified here (second line of that error snippet)? It's not in scope for my code.</p>



<a name="231253474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253474">(Mar 22 2021 at 01:18)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/73996">https://github.com/rust-lang/rust/pull/73996</a> says</p>
<blockquote>
<p>If a symbol name can only be imported from one place, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path to the last component.</p>
</blockquote>



<a name="231253487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253487">(Mar 22 2021 at 01:19)</a>:</h4>
<p>so it looks like it's because there's only one <code>Unique</code> in the standard library (<code>std::ptr::Unique</code>)</p>



<a name="231253490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253490">(Mar 22 2021 at 01:19)</a>:</h4>
<p>hmm</p>



<a name="231253491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253491">(Mar 22 2021 at 01:19)</a>:</h4>
<p>I guess we'll see how that plays out.</p>



<a name="231253536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253536">(Mar 22 2021 at 01:20)</a>:</h4>
<p>And there are multiple <code>RawVec</code>?</p>



<a name="231253557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253557">(Mar 22 2021 at 01:20)</a>:</h4>
<p>probably <code>std::</code> and <code>alloc::</code> if I had to guess</p>



<a name="231253563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253563">(Mar 22 2021 at 01:20)</a>:</h4>
<p>maybe — yeah, that</p>



<a name="231253583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253583">(Mar 22 2021 at 01:21)</a>:</h4>
<p>although it seems weird since it's private in both</p>



<a name="231253599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253599">(Mar 22 2021 at 01:21)</a>:</h4>
<p>I'm a little surprised that <code>Unique</code> isn't lower than <code>std</code>.</p>



<a name="231253611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253611">(Mar 22 2021 at 01:21)</a>:</h4>
<p>oh yeah I'm totally wrong, Unique is defined in <code>core</code></p>



<a name="231253614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253614">(Mar 22 2021 at 01:21)</a>:</h4>
<p>I don't know why RawVec isn't abbreviated then</p>



<a name="231253662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231253662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231253662">(Mar 22 2021 at 01:22)</a>:</h4>
<div class="codehilite"><pre><span></span><code>$ rg &#39;struct RawVec&#39; library/
library/alloc/src/raw_vec.rs
49:pub struct RawVec&lt;T, A: Allocator = Global&gt; {
$ rg &#39;struct Unique&#39; library/
library/core/src/ptr/unique.rs
36:pub struct Unique&lt;T: ?Sized&gt; {
</code></pre></div>



<a name="231271577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20determines%20if%20a%20type%20is%20unqualified%20in%20error%20output%3F/near/231271577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20determines.20if.20a.20type.20is.20unqualified.20in.20error.20output.3F.html#231271577">(Mar 22 2021 at 07:28)</a>:</h4>
<p>Adding <code>extern crate alloc</code> can make it unqualified: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=829cde47d47e7f5027c302c5240f4ad9">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=829cde47d47e7f5027c302c5240f4ad9</a><br>
It seems <code>RawVec</code> is not re-exported in <code>std</code>?</p>
<div class="codehilite" data-code-language="Bash Session"><pre><span></span><code><span class="gp">[library/std/src] $ </span>rg -F alloc::
<span class="go">alloc.rs</span>
<span class="go">17://! use std::alloc::{GlobalAlloc, System, Layout};</span>
<span class="go">70:pub use alloc_crate::alloc::*;</span>
<span class="go">81:/// use std::alloc::System;</span>
<span class="go">96:/// use std::alloc::{System, GlobalAlloc, Layout};</span>

<span class="go">error.rs</span>
<span class="go">22:use crate::alloc::{AllocError, LayoutError};</span>
<span class="go">591:impl Error for alloc::collections::TryReserveError {}</span>

<span class="go">lib.rs</span>
<span class="go">519:    pub use alloc::task::*;</span>

<span class="go">ffi/c_str.rs</span>
<span class="go">885:                //   - `alloc::Layout&lt;NonZeroU8&gt; == alloc::Layout&lt;u8&gt;`.</span>

<span class="go">io/impls.rs</span>
<span class="go">4:use crate::alloc::Allocator;</span>

<span class="go">sys_common/alloc.rs</span>
<span class="go">3:use crate::alloc::{GlobalAlloc, Layout, System};</span>

<span class="go">os/fortanix_sgx/mod.rs</span>
<span class="go">19:        pub use crate::sys::abi::usercalls::alloc::*;</span>

<span class="go">sys/hermit/alloc.rs</span>
<span class="go">1:use crate::alloc::{GlobalAlloc, Layout, System};</span>

<span class="go">sys/sgx/alloc.rs</span>
<span class="go">1:use crate::alloc::{GlobalAlloc, Layout, System};</span>
<span class="go">16:static DLMALLOC: SpinMutex&lt;dlmalloc::Dlmalloc&lt;Sgx&gt;&gt; =</span>
<span class="go">17:    SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));</span>
<span class="go">21:unsafe impl dlmalloc::Allocator for Sgx {</span>
<span class="go">91:    unsafe { crate::alloc::alloc(Layout::from_size_align_unchecked(size, align)) }</span>
<span class="go">97:    unsafe { crate::alloc::dealloc(ptr, Layout::from_size_align_unchecked(size, align)) }</span>

<span class="go">sys/sgx/args.rs</span>
<span class="go">16:        let args = unsafe { alloc::User::&lt;[ByteBuffer]&gt;::from_raw_parts(argv as _, argc as _) };</span>

<span class="go">sys/unix/alloc.rs</span>
<span class="go">1:use crate::alloc::{GlobalAlloc, Layout, System};</span>
<span class="go">3:use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};</span>

<span class="go">sys/unsupported/alloc.rs</span>
<span class="go">1:use crate::alloc::{GlobalAlloc, Layout, System};</span>

<span class="go">sys/wasm/alloc.rs</span>
<span class="go">19:use crate::alloc::{GlobalAlloc, Layout, System};</span>
<span class="go">21:static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();</span>

<span class="go">sys/windows/alloc.rs</span>
<span class="go">1:use crate::alloc::{GlobalAlloc, Layout, System};</span>
<span class="go">3:use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};</span>

<span class="go">sys/sgx/abi/panic.rs</span>
<span class="go">1:use super::usercalls::alloc::UserRef;</span>

<span class="go">sys/sgx/abi/usercalls/mod.rs</span>
<span class="go">21:        let mut userbuf = alloc::User::&lt;[u8]&gt;::uninitialized(total_len);</span>
<span class="go">43:        let mut userbuf = alloc::User::new_from_enclave(&amp;userbuf);</span>
<span class="go">57:        let mut userbuf = alloc::User::&lt;[u8]&gt;::uninitialized(total_len);</span>
<span class="go">84:fn string_from_bytebuffer(buf: &amp;alloc::UserRef&lt;ByteBuffer&gt;, usercall: &amp;str, arg: &amp;str) -&gt; String {</span>
<span class="go">93:        let addr_user = alloc::User::new_from_enclave(addr.as_bytes());</span>
<span class="go">94:        let mut local = alloc::User::&lt;ByteBuffer&gt;::uninitialized();</span>
<span class="go">106:        let mut bufs = alloc::User::&lt;[ByteBuffer; 2]&gt;::uninitialized();</span>
<span class="go">107:        let mut buf_it = alloc::UserRef::iter_mut(&amp;mut *bufs); // FIXME: can this be done</span>
<span class="go">122:        let addr_user = alloc::User::new_from_enclave(addr.as_bytes());</span>
<span class="go">123:        let mut bufs = alloc::User::&lt;[ByteBuffer; 2]&gt;::uninitialized();</span>
<span class="go">124:        let mut buf_it = alloc::UserRef::iter_mut(&amp;mut *bufs); // FIXME: can this be done</span>
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>